package com.example.login.Service;

import com.example.login.Mapper.GoodsMap;
import com.example.login.Mapper.MP3Map;
import com.example.login.Pojo.Goods;
import com.example.login.Pojo.MP3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("MP3Service")
public class MP3Service {
    @Autowired
    MP3Map mp3Map;
    @Autowired
    GoodsMap goodsMap;
    public boolean Add(String sku_code,String color,String ROM,String image,int price,int num,
                    int seller_id,String title,String store_name,String brand_name,int fright,String combination,String introduction){
        Goods goods=goodsMap.getGoodsBySellerIdAndTitle(seller_id,title);
        //first代表第一次插入
        boolean first=false;
        if(goods==null) {
            goodsMap.AddGoods(seller_id, title, store_name, brand_name, image, "MP3", fright,price);
            first=true;
        }
        Goods good=goodsMap.getGoodsBySellerIdAndTitle(seller_id,title);
        int id =good.getId();
        MP3 mp3=mp3Map.getMP3Information(id,sku_code);
        if(mp3!=null)
            return false;
        else
            mp3Map.Register(id, sku_code,color, ROM,image,price, num,combination,introduction);
        if(first)
        {
            goodsMap.updateGoodImage(id+sku_code+"/"+image,id);
        }
        if(goodsMap.getMinPrice(seller_id,title)>price)
            goodsMap.updateMin(seller_id,title,price);
        return true;
    }
}
